<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1000px">
        <div>
            <div>
                <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="70px">
                    <el-form-item label="店铺" prop="shop_id">
                        <el-select v-model="queryParams.shop_id" placeholder="请选择店铺" clearable size="small" style="width: 240px">
                            <el-option v-for="(dict, index) in shopList" :key="index" :label="dict.shop_name" :value="dict.shop_id" />
                        </el-select>
                    </el-form-item>
                    <el-form-item label=" ">
                        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div>
                <el-row :gutter="10" class="mb8">
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
                </el-row>
                <el-table v-loading="loading" :data="tableData" border script>
                    <el-table-column label="店铺名称" prop="shop_name"></el-table-column>
                    <el-table-column label="操作数量" prop="nums"></el-table-column>
                    <el-table-column label="创建时间" prop="create_time"></el-table-column>
                    <el-table-column label="操作人" prop="operater"></el-table-column>
                    <el-table-column label="状态" prop="status">
                        <template slot-scope="scope">
                            {{ scope.row.status == 1 ? '已执行': scope.row.status == 0 ? '执行中' :''}}
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList" />
        </div>
        <div slot="footer" class="dialog-footer"></div>
    </el-dialog>
</template>

<script>
import { messageLog, getShopList } from '@/api/customer'
export default {
    name: 'DetailDialog',
    components: {},
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
    },
    data() {
        return {
            loading: false,
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                shop_id: ''
            },
            shopList: []
        }
    },
    computed: {
        title() {
            return `执行日志记录`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    async created() {
        this.loading = true
        try {
            const result = await getShopList()
            this.shopList = result?.data ?? []
        } catch (error) {
            console.log(error)
            this.loading = false
        }
        this.queryParams.id = this.params.id
        this.getList()
    },
   
    methods: {
 
        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
        getList() {
            this.loading = true
            messageLog({ 
                ...this.pageInfo,
                shop_id: this.queryParams.shop_id,
                id: this.queryParams.id
            })
                .then(res => {
                    this.tableData = res.data?.list ?? []
                    this.total = res.data?.total ?? 0
                })
                .finally(() => {
                    this.loading = false
                })
        },
    },
}
</script>

<style></style>
